home *** CD-ROM | disk | FTP | other *** search
-
-
- #include "GraphicsModule_Types.h"
- #include "Sounds.h"
-
- #include <Picker.h>
- #include <Palettes.h>
-
-
- // these are the functs that need defined ...
- OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params);
- // these must be defined also
- OSErr DoSelected(RgnHandle blankRgn, short message, GMParamBlockPtr params);
- OSErr DoAboutBox(RgnHandle blankRgn, short message, GMParamBlockPtr params);
-
-
- struct foo {
- double a,b;
- struct foo *next;
- };
-
- //#define MAXX 480
- //#define MAXY 300
- #define MAXM 150 //400
-
- #define START_SATURATION 32767 //8192 //4096
-
- Boolean gDoColor = FALSE;
-
-
- int currentMonitor;
- void StepColor(SmallFract *theSaturation, SmallFract *theHue,
- short theSaturationDelta, short theDelta);
- unsigned short RangedRdm( unsigned short min, unsigned short max );
- unsigned short random(void);
-
- //////////////////////////////////////////////////////////////////////////////////////
- // this is the first funct called by AD ... we need to allocate and initialize here
- OSErr
- DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params) {
- Boolean HasColorQD(void);
-
- if (HasColorQD())
- gDoColor = TRUE;
- currentMonitor = 0;
- return noErr;
- }
-
- //////////////////////////////////////////////////////////////////////////////////////
- // the screen saver has been awakened! time to ditch the storage and wave goodbye
- OSErr
- DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params) {
-
- return noErr;
- }
-
-
-
- //////////////////////////////////////////////////////////////////////////////////////
- // make the screen go black
- OSErr
- DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params) {
-
- // darken the screen ...
- FillRgn(blankRgn, params->qdGlobalsCopy->qdBlack);
- return noErr;
-
- }
-
- //////////////////////////////////////////////////////////////////////////////////////
- // this is the workhorse routine. It does the continual screen work to make
- // this screen saver what it is.
- OSErr
- DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- Rect linesRect;
- short number, x, n;
- struct foo *top, *p, *p2;
- double mx, my, nx, ny;
- SmallFract theSaturation, theHue;
- short theSaturationDelta;
- short stepAmount;
- short maxVertices;
-
-
- BackColor( blackColor);
- ForeColor( whiteColor);
-
- linesRect = params->monitors->monitorList[currentMonitor].bounds;
-
- // every (user-settable) so often, erase the on-screen mess
- if (RangedRdm(0, 100) >= params->controlValues[1] )
- EraseRect( &linesRect);
-
- //was: number = (random() % 3) + 2;
- //number = (random() % 50) + 2;
- maxVertices = 4 + (params->controlValues[3] / 10);
- number = RangedRdm(2, maxVertices);
- x = 0;
-
- top = p = (struct foo *)NewPtr( sizeof(struct foo));
- while (x++ != number) {
- p->next = (struct foo *)NewPtr( sizeof(struct foo));
- if (p->next == NULL) {
- BlockMove( "\pNewPtr failed - oops lost some memory, too!",
- ¶ms->errorMessage[0], 15 );
- return ModuleError;
- }
- p = p->next;
- }
- p->next = top;
- p = top;
-
- //////////////////////////////////////
- // initial values for these
- mx = 0;
- my = 0;
- nx = 9999999.0; //• Large numbers for finding minimum value.
- ny = 9999999.0;
-
- do {
- p->a = (double) random ();
- if (p->a > mx) mx = p->a;
- if (p->a < nx) nx = p->a;
-
- p->b = (double) random ();
- if (p->b > my) my = p->b;
- if (p->b < ny) ny = p->b;
-
- p = p->next;
- } while (p != top);
-
- do {
- p->a = ((p->a - nx) * (linesRect.right-linesRect.left)) / (mx - nx);
- p->b = ((p->b - ny) * (linesRect.bottom-linesRect.top)) / (my - ny);
- p = p->next;
- } while (p != top);
-
- MoveTo ( linesRect.left + (int) p->a, linesRect.top + (int) p->b);
- if (gDoColor &&
- (params->monitors->monitorList[currentMonitor].curDepth > 2) ) {
- theSaturation = START_SATURATION;
- theHue = RangedRdm(0, 65535);
- }
-
-
- // I like this better (scalable)
- // it turns out that 1/100 of 1000 is 10
- // so ...
- theSaturationDelta = 10 * params->controlValues[0];
-
- //theSaturationDelta = (params->controlValues[0] / 10) * 100;
- // we go from { 0, 10, 20, ... 500 ... 1000 }
-
- n = 0;
- while (n++ < (MAXM * number) ) {
- //#define AMT 20
- #if 0
- p->a = (p->a * AMT + p->next->a) / (AMT+1);
- p->b = (p->b * AMT + p->next->b) / (AMT+1);
- #else
- stepAmount = 1 + (params->controlValues[2] / 5);
-
- p->a = (p->a * stepAmount + p->next->a) / (stepAmount+1);
- p->b = (p->b * stepAmount + p->next->b) / (stepAmount+1);
- #endif
- if (gDoColor &&
- (params->monitors->monitorList[currentMonitor].curDepth > 2) ) {
- StepColor(&theSaturation, &theHue, theSaturationDelta, (MAXM*number) );
- }
- LineTo ( linesRect.left + (int)p->a, linesRect.top + (int)p->b);
- p = p->next;
- }
-
- p = top; //• Clean up the circular linked list.
- do
- {
- p = (p2 = p)->next;
- DisposPtr ( (Ptr)p2);
- } while (p != top);
- //////////////////////////////////////
-
- // next time around, use the next monitor
- currentMonitor++;
- if (currentMonitor >= params->monitors->monitorCount)
- currentMonitor = 0;
-
- return noErr;
- }
-
- //////////////////////////////////////////////////////////////////////////////////////
- // this is called when they click on something in the control panel
- OSErr
- DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
- // button got pushed??
- return noErr;
- }
-
-
-
- OSErr DoSelected(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
- return noErr;
- }
-
-
-
- OSErr DoAboutBox(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
- return noErr;
- }
-
-
- void
- StepColor(
- SmallFract *theSaturation, SmallFract *theHue,
- short theSaturationDelta, short theDelta) {
- RGBColor rColor;
- HSVColor hColor;
-
-
- *theSaturation += ( (65535-START_SATURATION) / theDelta);
-
- *theHue += theSaturationDelta; //65535/theDelta;
- if (*theHue >= 65535)
- *theHue %= 65535;
-
- // any hue/color
- hColor.hue = *theHue;
-
- // lets just choose the brightest colors
- hColor.saturation = *theSaturation;
-
- // any only the brighter half values of it
- hColor.value = RangedRdm( 49150, 65535);
-
- HSV2RGB( &hColor, &rColor);
- RGBForeColor( &rColor); // pmForeColor() if you want to animate
- }
-
-